#pragma once

#include <iostream>
#include <pthread.h>

class Mutex
{
public:
    Mutex(pthread_mutex_t* lock_p = nullptr)
    :_lock_p(lock_p)
    {}
    void lock()
    {
        if(lock_p) pthread_mutex_lock(lock_p);
    }
    void unlock()
    {
        if(lock_p) pthread_mutex_unlock(lock_p);
    }
    ~Mutex()
    {}
private:
    pthread_mutex_t* _lock_p;
};

class LockGuard
{
public:
    LockGuard(pthread_mutex_t* mutex)
    :_mutex(mutex)
    {
        mutex.lock();
    }
    ~LockGuard()
    {
        mutex.unlock();
    }
private:
    Mutex _mutex;
};